import diff from "./diff"

export default function updateComponent(virtualDOM,oldComponent,oldDOM,container){
    // 组件更新
    oldComponent.componentWillReceiveProps(virtualDOM.props)
    if(oldComponent.shouldComponentUpdate(virtualDOM.props)){
        // 未更新前的props
        let prevProps = oldComponent.props
        oldComponent.componentWillUpdate(virtualDOM.props)

        // 组件更新
        oldComponent.updateProps(virtualDOM.props)
        // 获取组件返回的最新的 virtualDOM
        let nextVirtualDom = oldComponent.render()
        // 挂载更新最新virtualDOM上的component 供Diff获取
        nextVirtualDom.component = oldComponent
        diff(nextVirtualDom,container,oldDOM)

        oldComponent.componentDidUpdate(prevProps)
    }
    
}